package com.example.jdbcdemo;

import java.sql.*;

public class JDBCResult {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/jdbc_demo?serverTimezone=GMT&characterEncoding=UTF-8";
        String user = "root";
        String password = "123456";

        // SQL 查询语句
        String sql = "SELECT * FROM teacher where id > 0";

        try (Connection conn = DriverManager.getConnection(url, user, password);
             Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ) {
            // 执行查询
            try (ResultSet rs = stmt.executeQuery(sql)) {
                // 移动到倒数第二行
                rs.absolute(-2);

                System.out.println(rs.getInt("id") + " " + rs.getString("name"));
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
